package comp.part{
	import flash.events.Event;
	import flash.events.IOErrorEvent;
	import flash.net.URLLoader;
	import flash.net.URLRequest;
	import flash.net.URLRequestMethod;
	
	import mx.managers.CursorManager;

	public class HttpLoader{
		public var request:URLRequest;
		public var loader:URLLoader;
		public var successFuct:Function;
		public var showIOErrorPrompt:Boolean = true;
		public var showBusyCursor:Boolean = true;
		
		public function HttpLoader(url:String, data:Object=null, successFuct:Function=null){
			this.successFuct = successFuct;
			
			request = new URLRequest(url);
			request.method = URLRequestMethod.POST;
			request.data = data;
			
			loader = new URLLoader();
			loader.addEventListener(Event.COMPLETE, function(e:Event):void{
				CursorManager.removeBusyCursor();
				if(null != successFuct){
					successFuct(loader.data);
				}
			});
			loader.addEventListener(IOErrorEvent.IO_ERROR, function(e:IOErrorEvent):void{
				CursorManager.removeBusyCursor();
				if(showIOErrorPrompt){
					Prompt.show("Sorry，网络链接错误");
				}
			});
		}
	
		public function send():void{
			if(showBusyCursor){
				CursorManager.setBusyCursor();
			}
			loader.load(request);
		} 
		
	}
}